package netective.api.analyzer;

import java.util.ArrayList;

public enum PacketType {
	ARPPacket, ICMPPacket, IPPacket, TCPPacket, UDPPacket;
	
	private static PacketType[] packets = { ARPPacket, ICMPPacket, IPPacket, TCPPacket, UDPPacket };
	
	public static PacketType convertFromString(String name) {
		if (name.equals("ARPPacket")) {
			return ARPPacket;
		}
		if (name.equals("IPPacket")) {
			return IPPacket;
		}
		if (name.equals("TCPPacket")) {
			return TCPPacket;
		}
		if (name.equals("ICMPPacket")) {
			return ICMPPacket;
		}
		if (name.equals("UDPPacket")) {
			return UDPPacket;
		}
		return null;
	}
	
	public static PacketType[] getAllPacketTypes() {
		return packets;
	}
	
	public static PacketType[] getPacketTypesWithoutARP() {
		PacketType[] packetsTypes = {ICMPPacket, IPPacket, TCPPacket, UDPPacket };
		return packetsTypes;
	}
	
	public static PacketType[] getTCPAndUDPPackets() {
		PacketType[] packetTypes = { TCPPacket, UDPPacket };
		return packetTypes;
	}
	
	public static ArrayList<PacketType> getPacketTypesAsArrayList(PacketResult packetResult) {
		PacketType[] packets;
		switch (packetResult) {
		case TCP_AND_UDP:
			packets = getTCPAndUDPPackets(); break;
		case WITHOUT_ARP: 
			packets = getPacketTypesWithoutARP(); break;
		case ALL: 
			packets = getAllPacketTypes(); break;
		default: 
			packets = getAllPacketTypes(); break;
		}
		ArrayList<PacketType> result = new ArrayList<PacketType>();
		for (int i = 0; i < packets.length; i++) {
			result.add(packets[i]);
		}
		
		return result;
	}
	
	public enum PacketResult {
		ALL, WITHOUT_ARP, TCP_AND_UDP
	}
}

